package com.jinzw.demo

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.View
import android.widget.Button

import com.jinzw.jform.Form
import com.jinzw.jform.rows.*


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var btn = findViewById(R.id.fdd) as Button
        var form: Form = findViewById(R.id.formex) as Form


        form.create {

            section("Section1") {
                islines = true
                id = Api.i
                textRow {
                    id = 2
                    title = "姓名"
                    placeholder = "请输入姓名"
                    validator = { s ->
                        s != null && s.length > 3
                    }
                    customizeEditText { textRow, editText ->
                        editText.setBackgroundResource(0)
                        editText.gravity = Gravity.RIGHT

                    }


                    //listeners
                    addValueChangeListener<TextRow> { textRow, value ->
                        //change background following value, for example
                        //textRow.view?.background = ...
                    }
                    addOnViewCreatedListener<TextRow> { textRow ->

                    }
                }
                phoneRow {
                    id = 3
                    title = "手机号"
                    placeholder = "请输入手机号"
                    customizeEditText { textRow, editText ->
                        editText.setBackgroundResource(0)
                        editText.gravity = Gravity.RIGHT
                    }
                }


                phoneRow {
                    id = 4
                    title = "号"
                    placeholder = "请输入手机号"
                    customizeEditText { textRow, editText ->
                        editText.setBackgroundResource(0)
                        editText.gravity = Gravity.RIGHT
                    }
                }

                rightRow {
                    id = 6
                    title = "Date Row"
                    defaultDate = "请输入姓名"
                    value = "fff"
                    datePicker { dateRow, resultHandler -> startActivity(Intent(this@MainActivity, TwoActivity::class.java)) }

                }

                alertRow {
                    id = 7
                    title = "车辆类型"
                    defaultDate = BuildConfig.cartype
                    value = "fff"
                    alertTitle = BuildConfig.cartype
                    alertItem = arrayOf("轿车", "皮卡")

//                    datePicker { dateRow, resultHandler -> Log.d("去你大爷","去你大爷的") }

                }
                checkRow {
                    id = 8
                    title = "车辆类型"
                    value = false
//                    datePicker { dateRow, resultHandler -> Log.d("去你大爷","去你大爷的") }
                }
            }
        }

//        form.listenRowRule{ row: Row<*>, s: String ->
//            Log.d("日了狗了",s)
//
//        }
        btn.setOnClickListener {

            form.values()


        }

    }

}
